package com.xbackbone.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xbackbone.web.domain.Address;
import com.xbackbone.web.domain.Person;


@Controller

public class MainController {

	@RequestMapping("/controller/home")
	public String showHomePage(){
		return "/WEB-INF/index3.jsp";
	}
	
	@RequestMapping("/controller/person/{id}")
	public @ResponseBody Person getPerson(@PathVariable("id") String id){
		Person person = new Person();
		person.setId(id);
		person.setFirstName("axl");
		
		Address address = new Address();
		address.setAddressLine1(" 7944 Silo Drive");
		
		person.setAddress(address);
		return person;
	}
	
	
	@RequestMapping(value = "/controller/person", headers = {"accept=application/json"}, method = RequestMethod.POST)
	public @ResponseBody String saveNewPerson(@RequestBody Person person){
		System.out.println();
		return "";
	}
	
	@RequestMapping(value = "/controller/person/{id}", headers = {"accept=application/json"}, method = RequestMethod.PUT)
	public  @ResponseBody String  updatePerson(@RequestBody Person person){
		System.out.println();
		return "";
	}
	
	@RequestMapping("/controller/persons")
	public @ResponseBody List<Person> getAllPersons(){
		List<Person> allPersons = new ArrayList<Person>();
		Person person1 = new Person();
		person1.setFirstName("oleng");
		
		Address address = new Address();
		address.setAddressLine1(" 7944 Silo Drive");
		
		person1.setAddress(address);
		allPersons.add(person1);
		
		Person person2 = new Person();
		person2.setFirstName("lrama");
		
		Address address2 = new Address();
		address2.setAddressLine1(" 284 Park Drive");
		
		person2.setAddress(address2);
		allPersons.add(person2);
		
		return allPersons;
	}
}
